import akka.actor.ActorSystem
import akka.cluster.Cluster
import akka.pattern.Patterns.ask
import akka.stream.impl.fusing.Delay
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import scala.compat.java8.FutureConverters.toJava
import java.util.concurrent.CompletableFuture

fun main(args: Array<String>) {
//    val system = ActorSystem.create("localSystem", ConfigFactory.load("ping"))
//    val actorSelection = system.actorSelection("akka.tcp://test@127.0.0.1:2552/user/testakka")
//    val s = ask(actorSelection, "Ping", 1000)
//    val cs = toJava<Any>(s)
//    val j = cs as CompletableFuture<String>
//    j.thenCompose {
//        toJava<Any>(ask(actorSelection, it, 1000))
//    }.handle{x,t->
//        if (t != null)
//        {
//            println(t)
//        }
//    }
    val config = ConfigFactory.parseString(
            "akka.remote.netty.tcp.port=2552")
            .withFallback(ConfigFactory.load("cluster"))
    val clusterSystem = ActorSystem.create("ClusterSystem", config)
    clusterSystem.actorOf(ClusterAkka2.props(), "clusterAkka2")
}